/********************************************************************
	created:	2010/07/13
	created:	13:7:2010   17:05
	filename: 	D:\Proj\gcstock\code\C++\GCStock\Stock\GCStock.h
	file path:	D:\Proj\gcstock\code\C++\GCStock\Stock
	file base:	GCStock
	file ext:	h
	author:		Greg Song
	
	purpose:	
*********************************************************************/


#ifndef _GC_STOCK_H_
#define _GC_STOCK_H_
#include "GCHeader.h"
#include "GCTime.h"
#include "GCArray.h"
#include "GCRawDataParse.h"

namespace gcstock
{
    struct GCTradeRec
    {
        GCTimestamp time;
        GCFLOAT     price;
        GCINT       unit;
        int         action;
        GCFLOAT     amount;
        int         seq;
    };
    
    class GCDetailTrade
    {
    public:
        
        virtual void add(GCCHAR* rec) = 0;
        virtual GCTestString toString() = 0;
        virtual const GCTradeRec* operator [](GCINT index) = 0;
    protected:
        
    private:
        
    };
    
    class GCDetailTradeQQ:GCDetailTrade
    {
    public:
        GCDetailTradeQQ(){updateLimit = 200;lastSeq = 0;};
        ~GCDetailTradeQQ(){};
        void add(GCCHAR* recs);
        GCTestString toString();
        const GCTradeRec* operator [](GCINT index);
    protected:
        
    private:
        int curIndex;
        int updateLimit;
        int lastSeq;
        GCVArray<GCTradeRec*> recList;
        void insertIntoDB();
    };
    class GCStock
    {
    public:
        GCStock(){}
        ~GCStock(){}
        
        void add(GCCHAR* rec){if(rec){tradelist.add(rec);}}
        const GCCHAR* getName() {return name.c_str();}
        const GCINT   getCode() {return code;}
        const GCFLOAT getTotalAmt() {return total_amount;}
        const GCFLOAT getPrice(){return price;}
        
        void setName(const GCCHAR* n){name = n;}
        void setCode(const GCINT c){code = c;}
        void setTotalAmt(const GCFLOAT t){total_amount = t;}
        void setPrice(const GCFLOAT p){price = p;}
        GCTestString toString()
        {
            GCSStream str;
            str<<_GCT("GCStock::toString()");
            return str.str();
        }
    protected:
        
    private:
        GCTestString    name;
        GCINT           code;
        GCFLOAT         price;
        GCFLOAT         total_amount;
        GCDetailTradeQQ tradelist;
    };
    class GCStockMonitor
    {
    public:
        GCStockMonitor(){}
        virtual ~GCStockMonitor(){}
        
        virtual void parseFormat(IN GCCHAR* format, OUT GCINT& size) = 0;
        virtual void setParseFormat() = 0;
        virtual void parseLine(IN GCCHAR* rawData) = 0;
        
        virtual GCTestString toString() = 0;

        // Access method
        // By code
        virtual GCStock* operator[](GCINT code) = 0;
        
        // By name
        virtual GCStock* operator[](GCCHAR* name) = 0;

    protected:
        
    private:
        //GCVArray<GCParseElement*> arrayParsed;
        //GCDetailTradeQQ tradelist;
    };



    class GCStockMonitorQQ: public GCStockMonitor
    {
    public:
        GCStockMonitorQQ() {}
        virtual ~GCStockMonitorQQ(){}

        virtual void parseFormat(IN GCCHAR* format, OUT GCINT& size);
        virtual void setParseFormat();
        virtual void parseLine(IN GCCHAR* rawData);
        
        virtual GCTestString toString()
        {
            GCSStream str;
            str<<_GCT("GCStockMonitorQQ::toString()")<<gcendl;
            return str.str();
        };

        // Access method
        // By code
        virtual GCStock* operator[](GCINT code);

        // By name
        virtual GCStock* operator[](GCCHAR* name);
    protected:
        
    private:
        GCVArray<GCParseElement*> arrayParsed;
        GCVArray<GCStock*>        stockArray;        
    };
}

#endif // _GC_STOCK_H_